import java.util.Arrays;

public class Test1 {
    //leetcode 646 最长数对链
    public int findLongestChain(int[][] pairs) {
        Arrays.sort(pairs,(a,b) -> a[0] - b[0]);
        int n = pairs.length;
        //dp[i]表示以第i个位置为结尾的所有数对链中最长的长度
        int[] dp = new int[n];
        Arrays.fill(dp,1);
        int ret = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (pairs[j][1] < pairs[i][0]) {
                    dp[i] = Math.max(dp[j] + 1,dp[i]);
                    ret = Math.max(ret,dp[i]);
                }
            }
        }
        return ret;
    }
}
